var express = require('express');
var router = express.Router();
var CONFIG = require('../../../../common/config');
var CODE = require('../../../../common/code');
var superagent = require('superagent');
var sundryUtil = require('./util/sundryUtil');
var retUtil = require('./util/retUtil');





router.get('/',function (req, res, next) {
    res.send('respond with a sundry resource');
});


/***
 * 获取分类结构树
 * @author 毛凯
 * @date 2018-4-11
 * 方式: GET
 * 参数: userId   用户唯一标识
 * 参数: designKind  10 设计分类树,  20 视频分类树, 暂时固定10
 *测试地址 : http://localhost:3000/yjxc/yjscPlatform/design/v1/users/userLogin?accName=ddd&accPsw=dsfdsfdsfdsfdsfsdf
 */
function getTypeTree(req, res, next) {
    var userId = retUtil.numberFromReq(req, 'userId');
    var designKind = retUtil.numberFromReq(req, 'designKind') || 10;
    if (!userId || !designKind) {
        return retUtil.ret_err_json("参数有误", res);
    }

    sundryUtil.getTypeTree(designKind, function (err,data) {
        if(err){
            return retUtil.ret_err_json(err, res);
        }
        return retUtil.ret_succ_json(data, res);
    });

}
router.post('/getTypeTree', getTypeTree);
router.get('/getTypeTree', getTypeTree);

/***
 * 获取默认关键词列表
 * @author 毛凯
 * @date 2018-4-12
 * 方式: GET
 * 参数: userId   用户唯一标识
 *测试地址 : http://localhost:3000/yjxc/yjscPlatform/design/v1/sundry/getDefKwds?userId=32
 */
function getDefKwds(req, res, next) {
    var userId = retUtil.numberFromReq(req, 'userId');
    if (!userId) {
        return retUtil.ret_err_json("参数有误", res);
    }

    sundryUtil.getDefKwds(function (err,data) {
        if(err){
            return retUtil.ret_err_json(err, res);
        }
        return retUtil.ret_succ_json(data, res);
    });

}
router.post('/getDefKwds', getDefKwds);
router.get('/getDefKwds', getDefKwds);



/***
 * 获取插件最新下载地址
 * @author 毛凯
 * @date 2018-4-12
 * 方式: GET
 * 参数: device  平台: 1 标识一键生成iOS端, 2 标识一键生成android端, 3一键生成ai插件
 *测试地址 : http://localhost:3000/yjxc/yjscPlatform/design/v1/sundry/getPlatformVer?device=3
 */
function getPlatformVer(req, res, next) {
    var device = retUtil.numberFromReq(req, 'device');
    if (!device) {
        return retUtil.ret_err_json("参数有误", res);
    }

    sundryUtil.getPlatformVer(device,function (err,data) {
        if(err){
            return retUtil.ret_err_json(err, res);
        }
        return retUtil.ret_succ_json(data, res);
    });

}
router.post('/getPlatformVer', getPlatformVer);
router.get('/getPlatformVer', getPlatformVer);

//==========================================================================
module.exports = router;